namespace DevWeb.Biztalk.DeploymentSettings.Data.CodeFirst.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class ChangedUserDbEntry : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.UserEnvironmentRights",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        TargetEnvironmentID = c.Int(nullable: false),
                        UserEnvironmentId = c.Int(nullable: false),
                        Right = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.UserEnvironments", t => t.UserEnvironmentId, cascadeDelete: true)
                .ForeignKey("dbo.TargetEnvironments", t => t.TargetEnvironmentID, cascadeDelete: true)
                .Index(t => t.TargetEnvironmentID)
                .Index(t => t.UserEnvironmentId);
            
            CreateTable(
                "dbo.UserEnvironments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Username = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            AddColumn("dbo.DefaultSettingParameterValues", "LastUpdatedBy", c => c.String(defaultValue: "migration" ));
            AddColumn("dbo.IntegrationVersionParameterValues", "LastUpdatedBy", c => c.String(defaultValue: "migration"));
            AlterColumn("dbo.TargetEnvironments", "Name", c => c.String(maxLength: 50));
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserEnvironmentRights", "TargetEnvironmentID", "dbo.TargetEnvironments");
            DropForeignKey("dbo.UserEnvironmentRights", "UserEnvironmentId", "dbo.UserEnvironments");
            DropIndex("dbo.UserEnvironmentRights", new[] { "UserEnvironmentId" });
            DropIndex("dbo.UserEnvironmentRights", new[] { "TargetEnvironmentID" });
            AlterColumn("dbo.TargetEnvironments", "Name", c => c.String(maxLength: 10));
            DropColumn("dbo.IntegrationVersionParameterValues", "LastUpdatedBy");
            DropColumn("dbo.DefaultSettingParameterValues", "LastUpdatedBy");
            DropTable("dbo.UserEnvironments");
            DropTable("dbo.UserEnvironmentRights");
        }
    }
}
